/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package BLO;

import DAO.SubjectDAO;
import DTO.SubjectDTO;
import Util.ConnectionUtil;
import java.sql.Connection;
import java.util.ArrayList;

/**
 *
 * @author Arturia
 */
public class SubjectBLO {

    private Connection con;

    public ArrayList<SubjectDTO> getAllSubjects() {
        ArrayList<SubjectDTO> list = new ArrayList<SubjectDTO>();
        try {
            con = ConnectionUtil.getConnection();
            list = SubjectDAO.LoadDatabase(con, null);

        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }

    public boolean insertSubject(SubjectDTO subject) {
        con = ConnectionUtil.getConnection();
        if (SubjectDAO.insert(con, subject) > 0) {
            return true;
        }
        return false;
    }

    public boolean updateSubject(SubjectDTO subject) {
        con = ConnectionUtil.getConnection();
        if (SubjectDAO.update(con, subject) > 0) {
            return true;
        }
        return false;
    }

    public boolean deleteSubject(String deleteSubject) {
        con = ConnectionUtil.getConnection();
        if (SubjectDAO.delete(con, deleteSubject) > 0) {
            return true;
        }
        return false;
    }

    public ArrayList<SubjectDTO> getStudentSubjects(String studentID){
        ArrayList<SubjectDTO> list = new ArrayList<SubjectDTO>();
        try {
            con = ConnectionUtil.getConnection();
            list = SubjectDAO.getStudentSubjects(con, studentID);

        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }

    public ArrayList<SubjectDTO> getTeacherSubjects(String teacherID){
        ArrayList<SubjectDTO> list = new ArrayList<SubjectDTO>();
        try{
            con = ConnectionUtil.getConnection();
            list = SubjectDAO.getTeacherSubjects(con, teacherID);
        }catch(Exception e){
            e.printStackTrace();
        }
        return list;
    }
}
